package com.keyancompany.zhongbaopingtai;

import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.keyancompany.zhongbaopingtai.activity.BaseActivity;
import com.keyancompany.zhongbaopingtai.api.TeamAPI;
import com.keyancompany.zhongbaopingtai.model.BaseModel;
import com.keyancompany.zhongbaopingtai.model.EventBusEntity;
import com.keyancompany.zhongbaopingtai.utils.T;

import org.greenrobot.eventbus.EventBus;

import butterknife.Bind;
import butterknife.BindString;
import butterknife.OnClick;

/**
 * Created by firefox on 2017/5/24.
 */

public class TeamCreateActivity extends BaseActivity {
    @BindString(R.string.team_create_title)
    String title;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.team_create_name)
    EditText teamCreateName;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_team_create;
    }

    @Override
    protected int getMenuId() {
        return 0;
    }

    @Override
    protected void initToolBar() {

        initToolBar(toolbar,title);
    }

    @Override
    protected void setUpViews() {

    }

    @OnClick(R.id.submit)
    public void toSubmit(View view) {
        String name = teamCreateName.getText().toString();
        if (TextUtils.isEmpty(name)) {
            T.showShort(mContext, "请输入团队名称！");
            return;
        }
        TeamAPI.newTeam(name, this, getLoading(R.string.watting_hint));
    }

    @Override
    public void success(int type, String json) {
        super.success(type, json);
        BaseModel base = validateJson(json);
        if (base != null) {
            T.showShort(mContext, base.msg);
            if (base.isSuccess()) {
                EventBus.getDefault().post(new EventBusEntity(EventBusEntity.Type.REFRENCE_TEAM));
                finish();

            }
        }
    }
}
